// pages/cart/index.js
import {
  openSetting,
  getSetting,
  chooseAddress,
  showModal,
  showToast,
} from "../../utils/asyncWx.js";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    cart: [],
    address: {},
    totalPrice: 0,
    totalNum: 0
  },
  onShow: function () {
    let cart = wx.getStorageSync("cart") || [];
    // 获取选中的商品
    cart = cart.filter((v) => v.checked);
    let address = wx.getStorageSync("address");
    if (address) {
      address.all =
        address.provinceName +
        address.cityName +
        address.countyName +
        address.detailInfo;
    }
    // 总价格 总数量
    let totalPrice = 0;
    let totalNum = 0;
    // 遍历商品数据
    cart.forEach((element) => {
      // 计算选中商品价格
      totalPrice += element.num * element.goods_price;
      totalNum = element.num;
    });
    this.setData({
      cart,
      totalNum,
      totalPrice,
      address,
    });
  },
  handleOrderPay(){
    const token =wx.getStorageSync('token')
    if(!token){
      wx.navigateTo({
        url: '/pages/auth/index',
      }); 
    }else{

    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
